package health.lm.com.mine.pop.circle;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;

import health.lm.com.component_base.widget.CustomPopWindow;
import health.lm.com.mine.R;
import health.lm.com.mine.activity.SettingActivity;
import health.lm.com.mine.model.MineModel;
import health.lm.com.network.callback.SimpleCallBack;


/**
 * 我要加圈确认
 * @author GQI
 */
public class ChangeInfoServicePopUtil {
    public static ChangeInfoServicePopUtil upLevelPopUtil;
    private CustomPopWindow popWindow;

    private ChangeInfoServicePopUtil() {
    }

    public static ChangeInfoServicePopUtil getInstance(){
        if (null == upLevelPopUtil) {
            upLevelPopUtil = new ChangeInfoServicePopUtil();
        }
        return upLevelPopUtil;
    }


    /**
     * 显示popwindow
     */
    public void init(SettingActivity context, int type, View mLayoutPopup) {
        View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_change_info_service, null);
        //确定
        TextView tv_submit = contentView.findViewById(R.id.tv_submit);
        //标题
        TextView tv_title = contentView.findViewById(R.id.tv_title);
        EditText editText = contentView.findViewById(R.id.et_code);
        if(type == 3){
            tv_title.setText("个人简介");
        }else  if(type == 4){
            tv_title.setText("服务内容");
        }
        popWindow = new CustomPopWindow.PopupWindowBuilder(context)
                .setView(contentView)
                .enableBackgroundDark(true)
                .setBgDarkAlpha(0.3f)
                .setAnimationStyle(R.style.pop_bottom_anim)
                //显示大小
                .size(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
                .create()
                .showAtLocation(mLayoutPopup, Gravity.CENTER, 0, 0);
        contentView.findViewById(R.id.rl_main).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindow.dissmiss();
            }
        });
        tv_submit.setOnClickListener(v ->{
            if(StringUtils.isEmpty(editText.getText().toString())){
                ToastUtils.showShort("请填写您要更改的内容");
                return;
            }
            MineModel.getInstance().changeSetting(type,editText.getText().toString(), new SimpleCallBack<Object>() {
                @Override
                public void onSuccess(Object o) {
                    popWindow.dissmiss();
                    context.notifyData();

                }
            });

        });

    }

}
